package com.tuozixuan.camel.springredis;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.redis.RedisConstants;
import org.springframework.data.redis.core.RedisCommand;
import org.springframework.stereotype.Component;

/**
 * 
 * https://www.cnblogs.com/d1012181765/p/15338436.html  
 * https://github.com/monodot/camel-demos/blob/master/examples/spring-boot/rest-service/src/main/java/xyz/tomd/cameldemos/springboot/restdsl/RestDslRouteBuilder.java  
 */
@Component
public class SpringRedisDemoRoute extends RouteBuilder {

	@Override
	public void configure() {
		
		from("timer://foo?repeatCount=1").
        setHeader(RedisConstants.KEY, constant("myname")).
        setHeader(RedisConstants.VALUE, constant("weng.weng")).
        setHeader(RedisConstants.COMMAND, constant(RedisCommand.SET)).to("spring-redis://192.168.80.97:6379?redisTemplate=#redisTemplate");
		
		from("timer://foo?repeatCount=1").
        setHeader(RedisConstants.KEY, constant("myname")).
        setHeader(RedisConstants.COMMAND, constant(RedisCommand.GET)).to("spring-redis://192.168.80.97:6379?redisTemplate=#redisTemplate").to("stream:out");
		
		
		Map<String, Object> info = new HashMap<>();
		info.put("myname1", "weng.weng1");
		info.put("myname2", "weng.weng2");
		from("timer://foo?repeatCount=1").
        //setHeader(RedisConstants.KEYS, constant(Arrays.asList("myname1", "myname2"))).
        setHeader(RedisConstants.VALUES, constant(info)).
        setHeader(RedisConstants.COMMAND, constant(RedisCommand.MSET)).to("spring-redis://192.168.80.97:6379?redisTemplate=#redisTemplate");
		
		from("timer://foo?repeatCount=1").
        setHeader(RedisConstants.FIELDS, constant(Arrays.asList("myname1", "myname2"))).
        setHeader(RedisConstants.COMMAND, constant(RedisCommand.MGET)).to("spring-redis://192.168.80.97:6379?redisTemplate=#redisTemplate").convertBodyTo(String.class).to("stream:out");
	}
	

}
